package com.dongan.service.impl;
import com.dongan.mapper.FileMapper;
import com.dongan.pojo.Codes;
import com.dongan.mapper.CodesMapper;
import com.dongan.pojo.File;
import com.dongan.service.CodesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dongan.service.FileService;
import com.dongan.utils.NumberFormatUtil;
import com.dongan.utils.SerialNumber;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 文件 服务实现类
 *
 * @author longTao
 * @since 2021-06-15
 */
@Service
public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements FileService {
    @Resource
    private FileMapper mapper;

    /**
     * 物理删除
     *
     * @param id
     * @return
     */
    @Override
    public boolean recoveryCFile(Long id) {
        return mapper.recoveryC(id)>0?true:false;
    }

    /**
     * @param designModuleTag 设计标签
     * @param type            类型
     * @param checkTag        复核
     * @param firstId         一级id
     * @param secondId        二级id
     * @param threeId         三级id
     * @param name            产品名
     * @param deleted         删除表志
     * @param pageNum         页码
     * @param pageSize        条数
     * @return
     */
    @Override
    public List<File> queryTheDataThatHasBeenDeleted(String designModuleTag, String type, String checkTag, Integer firstId, Integer secondId, Integer threeId, String name, Integer deleted, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<File> list = mapper.queryTheDataThatHasBeenDeleted(designModuleTag, type, checkTag, firstId, secondId, threeId, "%"+name+"%", deleted);
        return list;
    }

    /**
     * 恢复
     *
     * @param id
     * @return
     */
    @Override
    public boolean restore(Long id) {
        int i = mapper.restore(id);
        return i>0?true:false;
    }

    /**
     * 添加产品档案
     *
     * @param file
     * @return
     */
    /*@Override
    public boolean addFile(File file) {
        String pID=100+file.getFirstKindId()+file.getSecondKindId()+file.getThirdKindId()
                + NumberFormatUtil.numberFormat(6, SerialNumber.fileSN);
        file.setProductId(pID);
        file.setCheckTag("S001-0");
        int row=mapper.insert(file);
        if(row>0){
            SerialNumber.fileSN+=1;
            return true;
        }
        return false;
    }*/

    /**
     * 审核产品
     *
     * @param file
     * @return
     */
    /*@Override
    public boolean checkFile(File file) {
        //获得系统时间.
        Date date = new Date();
        SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
        String nowTime = sdf.format(date);
        Date time=null;
        try {
            time = sdf.parse(nowTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(time);
        file.setCheckTime(time);
        int row=mapper.updateById(file);

        return row>0?true:false;
    }*/

    /**
     * 修改产品
     *
     * @param file
     * @return
     */
    /*@Override
    public boolean updateFile(File file) {

        int row=mapper.del(file);

        return row>0?true:false;
    }*/


}
